package com.example.demo.web;

import com.example.demo.domian.User;
import com.example.demo.repository.UserRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user")
@Api(value = "用户相关接口",description = "用户相关接口")
public class UserController {
    @Autowired
    UserRepository userRepository;

    @GetMapping("/{id}")
    @ApiOperation("根据ID查找一个用户")
    public Object findOne(@PathVariable String id){
        return userRepository.findOne(id);
    }

    @GetMapping("/")
    @ApiOperation("获取所有用户")
    public Object findAll(){
        return userRepository.findAll();
    }

    @PostMapping("/save")
    @ApiOperation("保存/更新 用户")
    public Object save(@RequestBody User user){
        return userRepository.save(user);
    }

    @DeleteMapping("/{id}/del")
    @ApiOperation("删除用户")
    public Object remove(@PathVariable String id){
        userRepository.delete(id);
        return true;
    }
}
